var pageii = null;
var grid = null;
$(function () {
    function getOrderStatusText(status) {
        if (status == '1') {
            return '待支付';
        } else if (status == '2') {
            return '待发货';
        } else if (status == '3') {
            return '已发货';
        } else if (status == '4') {
            return '<span style="color: green;">已完成</span>';
        } else if (status == '5') {
            return '已退款';
        } else if (status == '6') {
            return '已删除';
        } else if (status == '7') {
            return '已失效';
        }
        return '未定义';
    }

    grid = lyGrid({
        id: 'paging',
        l_column: [{
            colkey: "id",
            name: "id",
            width: "50px",
            hide: true
        }, {
            colkey: "code",
            name: "订单编码"
        }, /*{
            colkey: "good_name", // loaded from good
            name: "商品名称"
        }, {
            colkey: "count",
            name: "商品数量"
        },*/ {
            colkey: "order_money",
            name: "订单金额(元)"
        }, {
            colkey: "paymonny",
            name: "实付金额(元)"
        }, {
            colkey: "dou_money",
            name: "积分抵扣(元)"
        }, /*{
            colkey: "balance_money",
            name: "余额抵扣(元)"
        }, {
            colkey: "voucher_money", // loaded from voucher
            name: "代金券抵扣(元)"
        }, {
            colkey: "douback",
            name: "返积分数量(个)"
        }, */{
            colkey: "createtime",
            name: "下单时间"
        }, {
            colkey: "status",
            name: "状态",
            width: "100px",
            renderData: function (rowindex, data, rowdata, column) {
                return getOrderStatusText(data);
            }
        },{
            colkey: "addr_id",
            name: "邮寄地址",
             renderData: function (rowindex, data, rowdata, column) {
                 return "<a href='javascript:addrdetail(\""+data+"\");'>邮寄地址</a>";
             }
        },{
            colkey: "code",
            name: "商品详情",
            renderData: function (rowindex, data, rowdata, column) {
                return "<a href='javascript:goodsdetail(\""+data+"\");'>商品詳情</a>";
            }
        }],
        jsonUrl: rootPath + '/store/order/findByPage.shtml',
        dymCol: true,
        checkbox: true
    });

    $("#search").click("click", function () { // 绑定查询按扭
        var searchParams = $("#searchForm").serializeJson(); // 初始化传参数
        grid.setOptions({
            data: searchParams
        });
    });

    $("#confirmDeliveryFun").click("click", function () {
        confirmDeliveryFun();
    });
});

function confirmDeliveryFun() {
    debugger;
    var cbox = grid.getSelectedCheckbox();
    var selectRow = grid.selectRow();
    if (cbox.length > 1 || cbox == "") {
        layer.msg("只能选中一个");
        return;
    }
    var status = selectRow[0].status;
    if(status!=2){
        layer.msg("该订单不符合发货要求");
        return;
    }

    pageii = layer.open({
        title: "编辑",
        type: 2,
        area: ["600px", "80%"],
        content: rootPath + '/store/order/confirmDeliveryUI.shtml?id=' + cbox
    });
}

function goodsdetail(orderid) {
    pageii = layer.open({
        title: "商品详情",
        type: 2,
        area: ["600px", "80%"],
        content: rootPath + '/dsg/ordercar/goodsView.shtml?orderid=' + orderid
    });
}

function addrdetail(addrid) {
    debugger;
    pageii = layer.open({
        title: "地址详情",
        type: 2,
        area: ["800px", "50%"],
        content: rootPath + '/store/order/addrView.shtml?addrid=' + addrid
    });
}
